package com.example.qlexpress.customize;

import com.ql.util.express.Operator;
import com.ql.util.express.exception.QLException;

public class OperatorForAvg extends Operator {
	public OperatorForAvg(String name) {
		this.name = name;
	}

	@Override
	public Object executeInner(Object[] list) throws Exception {
		if (list.length == 0) {
			throw new QLException("操作数异常");
		}
		Object result = list[0];
		Double sum = 0.d;
		int length = list.length;
		for (int i = 0; i < length; i++) {
			Object o = list[i];
			if(o instanceof Integer){
				sum += (Integer)o;
			}else if(o instanceof Long){
				sum += (Long)o ;
			}else if(o instanceof Double){
				sum += (Double)o;
			}else{
				throw new Exception("不支持的参数类型{"+o+"}");
			}
		}
		return sum/length * 1.0;
	}
}
